package io;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author Cheng Jun
 * @version 1.0
 * Description: 字符输入流
 * @date 2019/10/23 14:32
 */
public class ReaderExample {

    public static void main(String[] args) {
        try {
            FileReader readmeFileReader = new FileReader("D:\\gitee\\java\\src\\io\\readme.txt");
            System.out.println(readmeFileReader.getEncoding());
            // 也有按照字符数组来读的方法
            int content = readmeFileReader.read();
            while (content != -1) {
                char chinese = (char) content;
                System.out.print(chinese);
                content = readmeFileReader.read();
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            System.out.println("end");
        }
    }
}
